package com.baimawangzi.recovery.servlet.courier;

import com.baimawangzi.recovery.bean.Courier;
import com.baimawangzi.recovery.service.impl.CourierServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/courieradd.do")
public class CourierAddServlet extends HttpServlet {
    @Override
    public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CourierServiceImpl courierService = new CourierServiceImpl();
        //解析url参数
        String couriername=req.getParameter("couriername");
        String status=req.getParameter("status");
        String sphonenum=req.getParameter("phonenum");

        Courier courier = new Courier(0, couriername, status, Long.parseLong(sphonenum));
        int a = courierService.add(courier);
        if(a>0){//返回的信息
            req.setAttribute("msg","添加快递员成功");
        }
        else {
            req.setAttribute("msg","添加快递员失败请检查输入的数据");
        }
        req.getRequestDispatcher("courierlist.do").forward(req,resp);

    }
}
